﻿using System;

namespace Borg
{
    [Serializable]
    public abstract class MetaElement
    {
        private int _id;
        private string _name;

        public int Id
        {
            get { return _id; }
            internal set {_id = value; } 
        }

        public string Name
        {
            get { return _name; }
            internal set { _name = value; }
        }

        public AssemblyElement AssemblyElement
        {
            get { return GetAssemblyElement(); }
        }

        public Runtime Runtime
        {
            get { return GetAssemblyElement().runtime; }
        }

        internal TypeStore TypeStore
        {
            get { return GetAssemblyElement().runtime.TypeStore; }
        }

        internal Composer Composer
        {
            get { return GetAssemblyElement().runtime.Composer; }
        }

        internal InstanceStore InstanceStore
        {
            get { return GetAssemblyElement().runtime.InstanceStore; }
        }

        internal Qualifier Qualifier
        {
            get { return GetAssemblyElement().runtime.Qualifier; }
        }

        internal Notifier Notifier
        {
            get { return GetAssemblyElement().runtime.Notifier; }
        }

        internal Logger Logger
        {
            get { return GetAssemblyElement().runtime.Logger; }
        }

        internal MetaElement(int id, string name)
        {
            Name = string.Intern(name);
            Id = id;
        }

        public override string ToString()
        {
            return string.Format("{0} [{1}:'{2}']", GetType().Name, Id, Name);
        }

        internal abstract AssemblyElement GetAssemblyElement();
    }
}
